#!/bin/bash

year=2001
month=2
day=28
hour=23
min=59
sec=56

while true
do
	if ( ((year%400==0)) )
	then
		feb=29
	else
		feb=28
	fi

	if [ $sec -le 58 ]
	then
   		((sec++))
		printf "%4d-%02d-%02d %02d:%02d:%02d\r" $year $month $day $hour $min $sec
		sleep 1
	else
		sec=0
		if [ $min -le 58 ]
		then
			((min++))
		else
			min=0
			if [ $hour -le 22 ]
			then
				((hour++))
			else
				hour=0
				case $month in
					1|3|5|7|8|10|12)
						days=30
						;;
					4|6|9|11)
						days=29
						;;
					2)
						case $feb in
							29)
								days=28
								;;
							28)
								days=27
								;;
						esac
						;;
				esac
				if [ $day -le $days ]
				then
					((day++))
				else
					day=1
					if [ $month -le 11 ]
					then
						((month++))
					else
						month=1
						((year++))
					fi
				fi
			fi
		fi
	fi
done
